package com.lys.controller;


import com.lys.service.DataClient;
import com.lys.service.WeatherReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/report")
public class WeatherReportController {

    @Autowired
    private WeatherReportService weatherReportService;
    @Autowired
    private DataClient dataClient;
    @RequestMapping(value = "cityKey/{key}",method = RequestMethod.GET)
    public ModelAndView getDataByCityKey(@PathVariable("key") String key, Model model){
        model.addAttribute("title","天气预报");
        model.addAttribute("cityId",key);
        model.addAttribute("report",weatherReportService.getDataByCityKey(key));
        try {
            //TODO
            model.addAttribute("cityList",dataClient.cityList());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ModelAndView("weather/report","reportModel",model);
    }
}
